<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

aos_header( 'User settings' );

$query = "SELECT * FROM users WHERE user_id = " . $_SESSION[ 'user_id' ];
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$row = mysql_fetch_array( $result, MYSQL_ASSOC );

if( isset( $_SESSION[ 'settings_status' ] ) ) {
	print( "\t\t\t\t<div class=\"blok\">\r\n\t\t\t\t" . $_SESSION[ 'settings_status' ] . "\r\n\t\t\t\t</div><br />\r\n" );
	unset( $_SESSION[ 'settings_status' ] );
}
?>
			<form action="save_settings.php" id="settings" method="post">
				<div class="blok">
					<strong><?php transprint( "Account settings" ); ?>:</strong><br />
					<?php transprint( "Gameplay settings" ); ?><br />
<?php 
if( $row[ 'auto_refresh' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"auto_refresh\"" . $checked . " /> " . translate ( "Auto refresh every 10 minutes" ) . "<br />\r\n" );
print( "\t\t\t\t\t\t<small>(" . translate ( "Will only auto refresh the overview page, military activity page and trade page" ) . ")</small><br />\r\n" );

if( $row[ 'show_village_image' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input id=\"show-village-image\" type=\"checkbox\" name=\"show_village_image\"" . $checked . " /> <label for=\"show-village-image\">" . translate ( "Show village image on village page" ) . "</label><br />\r\n" );

if( $row[ 'highlight_history' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"highlight_history\"" . $checked . " /> " . translate ( "Highlight date on new history events" ) . "<br />\r\n" );
print( "\t\t\t\t\t\t<small>(" . translate ( "History events tell something about the game world" ) . ")</small><br />\r\n" );
if( $row[ 'threaded_letters' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"threaded_letters\"" . $checked . " /> " . translate ( "Threaded letters" ) . "<br />\r\n" );
print( "\t\t\t\t\t\t<small>(" . translate ( "Hide replies to letters under their parent" ) . ")</small><br />\r\n" );

if( $row[ 'show_medals' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"show_medals\"" . $checked . " /> " . translate ( "Show my medals" ) . "<br />\r\n" );
print( "\t\t\t\t\t\t<small>(" . translate ( "Allows everyone in the game to see what medals you have earned" ) . ")</small><br />\r\n" );

if( $row[ 'end_username' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"end_username\"" . $checked . " /> " . translate ( "Show my username in the hall of fame" ) . "<br />\r\n" );
print( "\t\t\t\t\t\t<small>(" . translate ( "If you end up in the hall of fame at the end of the round your username can be added to your ruler name" ) . ")</small><br />\r\n" );
?>
						<input type="checkbox" name="officer_suggest_global" id="officer-suggest-global" value="officer_suggest_global"<?php print( $row[ 'officer_suggest_global' ] == '1' ? ' checked="checked"' : '' ); ?> /> <label for="officer-suggest-global"><?php transprint( 'Suggest officer names from all regions' ); ?></label> <small>(<?php transprint( 'If not checked officer names are suggested based on language setting' ) ?>)</small><br />
						<br />
<?php

if( $row[ 'premium' ] > 0 ) {
?>
						<input type="checkbox" name="show_promotion_tab" id="show-promotion-tab" value="show_promotion_tab"<?php print( $row[ 'show_promotion_tab' ] == '1' ? ' checked="checked"' : '' ); ?> /> <label for="show-promotion-tab"><?php transprint( 'Show promotion tab' ); ?></label><br />
						<br />
						<?php transprint( "Army name base" ); ?><br />
						<input type="text" name="army_names" value="<?php print( $row[ 'army_names' ] ); ?>" /><br />
						<small><?php transprint( 'This will be used as suggested army names for new armies. If you use "Infantry" for example, it will suggest: 1st Infantry, 2nd Infantry, etc.<br /> If this field is left empty, random army names will be suggested.' ); ?></small><br />
<?php
}
?>
						<br />
						<?php transprint( 'E-mail address' ); ?><?php print( $row[ 'email' ] != '' ? ' (' . translate( 'locked' ) . ')' : '' ); ?><br />
						<input size="40" type="text" name="email" value="<?php print( $row[ 'email' ] ); ?>"<?php print( $row[ 'email' ] != '' ? ' disabled="true"' : '' ); ?> /><br />
						<br />

<?php
print( "\t\t\t\t\t\t" . translate ( "E-mail notifications on" ) . ":<br />\r\n" );
if( $row[ 'inactivity_notification' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"inactivity_notification\"" . $checked . " /> " . translate ( "time to take action" ) . "<br />\r\n" );
if( $row[ 'letters' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"letters\"" . $checked . " /> " . translate ( "new ingame messages" ) . "<br />\r\n" );
if( $row[ 'civilian_news' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"civilian_news\"" . $checked . " /> " . translate ( "news about my capital and villages" ) . "<br />\r\n" );
if( $row[ 'operations_news' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"operations_news\"" . $checked . " /> " . translate ( "news about army movement and missions" ) . "<br />\r\n" );
if( $row[ 'military_news' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"military_news\"" . $checked . " /> " . translate ( "news about battles" ) . "<br />\r\n" );
if( $row[ 'news_letter' ] == '1' ) {
	$checked = " checked";
}
else {
	$checked = "";
}
print( "\t\t\t\t\t\t<input type=\"checkbox\" name=\"news_letter\"" . $checked . " /> " . translate ( "Newsletter <small>(New round announcements and game changes)</small>" ) . "<br /><br />\r\n" );
print( "\t\t\t\t\t\t" . translate ( "Information about me" ) . ":<br /><small>(" . translate ( "You will be able to share this information with your buddies" ) . ")</small><br />" .
		"\r\n\t\t\t\t\t\t<textarea cols=\"40\" name=\"info\" rows=\"5\">" . stripslashes( stripslashes( $row[ 'info' ] ) ) . "</textarea><br />\r\n" );

$query = "SELECT * " .
		"FROM languages " .
		"ORDER BY default_language DESC, language ASC";
//print( "Query: $query<br />" );
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$num = mysql_numrows( $result );
if( $num > 0 ) {
?>
		<br /><?php transprint( "Select your prefered language" ); ?>:<br />
		<select name="language">
<?php 
	while ( $row = mysql_fetch_object( $result ) ) {
		$selected = "";
		if( $row->language == $language ) {
			$selected = "selected=\"selected\" ";
		}
		print( "<option " . $selected . "value=" . $row->language . ">" . $row->title . " (" . $row->language . ")</option>" );
	}
?>
		</select><br />
		<small>(<?php transprint( 'Note: English is the games official language, others are community maintained' ); ?>)</small><br />
<?php
}

if( isset( $_SESSION[ 'password_status' ] ) ) {
	print( "\t\t\t\t\t\t<br />\r\n\t\t\t\t\t\t" . $_SESSION[ 'password_status' ] . "<br />\r\n" );
	unset( $_SESSION[ 'password_status' ] );
}
?>					
							<br />
							<strong>
								<?php transprint( 'Change password' ); ?>
							</strong>
							<br />
							<small>
								(<?php transprint( 'If you don\'t fill in anything your password will remain the same' ); ?>)
							</small>
							<br />
							<table id="half">
								<tr>
									<td><?php transprint( 'Old password' ); ?></td>
									<td><input type="password" name="password_old" size="20" /></td>
								</tr>
								<tr>
									<td><?php transprint( 'New password' ); ?></td>
									<td><input type="password" name="password_new" size="20" /></td>
								</tr>
								<tr>
									<td><?php transprint( 'Confirm password' ); ?></td>
									<td><input type="password" name="password_confirm" size="20" /></td>
								</tr>
							</table>
							<input type="button" id="save" name="save" value="<?php transprint( 'Save changes' ); ?>" onclick="disableElement( 'save', 'settings', 'button' );" />
							<input type="hidden" name="button" id="button" />
						</div>
<?php
$query = "SELECT start_turn FROM ruler WHERE ruler_id = " . $_SESSION[ 'ruler_id' ];
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$row = mysql_fetch_array( $result, MYSQL_ASSOC );
$start_turn = $row[ 'start_turn' ];
$query = "SELECT turn FROM game";
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$row = mysql_fetch_array( $result, MYSQL_ASSOC );

if( ( isset( $_SESSION[ 'admin' ] ) && $_SESSION[ 'admin' ] == 1 ) || $start_turn + 96 < $row[ 'turn' ] ) {
?>
						<br />
						<div class="blok">
							<input type="checkbox" id="resign-checkbox" onchange="checkRageQuiting()" name="resign" /> <label for="resign-checkbox"><?php transprint( 'I want to resign' ); ?></label><br />
							<small>
								(<?php transprint( 'You won\'t be able to access your stats, villages, armies, etc anymore, you will be able to create a new ruler and start from scratch' ); ?>.)
							</small><br />
							<input type="button" id="resign_confirm" name="resign_confirm" value="<?php transprint( 'Confirm resignation' ); ?>" onclick="disableElement( 'resign_confirm', 'settings', 'button' )" /><br />
						</div>
<?php
}
?>
					</form>
					<script type="text/javascript">
						function checkRageQuiting() {
							var checkbox = document.getElementById( "resign-checkbox" );
							if( checkbox.checked ) {
								var confirmed = confirm( "<?php transprint( 'Are you sure you want to resign?' ); ?>\n" +
										"<?php transprint( 'Perhaps you can take a break from the game and check back later.' ); ?>\n" +
										"<?php transprint( 'If you are still determined to resign press OK and confirm resignation.' ); ?>" );
								if( !confirmed ) {
									checkbox.checked = false;
								}
							}
						}
					</script>
<?php
aos_footer();
?>